package indi.flynn.zhouyi.collection;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class SubListExample {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("遥远的救世主");
        list.add("背叛");
        list.add("天幕红尘");
        list.add("人生");
        list.add("平凡的世界");

        List<String> subList = list.subList(3, 5);
        System.out.println(list);
        System.out.println(subList);


        List<String> newSubList = subList.stream().collect(Collectors.toList());

        // 往原集合中添加元素
        list.add("早晨从中午开始");

        // newSubList不会报错
        System.out.println(newSubList);
        // subList遍历会报错
        System.out.println(subList);
    }
}
